package com.ssps.back.platform.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssps.back.platform.service.InformationService;
import com.ssps.entity.Information;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author li
 * @time 2020/07/23 19:18:11
 */

@Controller
@RequestMapping("information")
public class InformationController {

    @Autowired
    InformationService informationService;

    @RequestMapping("informationList")
    public String InformationList(){
        return "/information/informationList";
    }

    @ResponseBody
    @RequestMapping("findAll")
    public Map<String,Object> InformationFIndAll(@RequestParam(name = "pageNum",defaultValue = "1") Integer pageNum, @RequestParam(name = "pageSize",defaultValue = "5") Integer pageSize ,String status,String rplate){
        Map<String,Object> map =new HashMap<>();
        try {
            PageHelper.startPage(pageNum,pageSize);
            List<Information> informationList=informationService.InformationFindAll(status,rplate);
            PageInfo<Information> pageInfo=new PageInfo<>(informationList);
            map.put("pageInfo",pageInfo);
            map.put("informationList",informationList);
            map.put("result",true);
        } catch (Exception e) {
            map.put("result",false);
            e.printStackTrace();
        }
        return map;
    }


    @ResponseBody
    @RequestMapping("updateAudit")
    public Map<String,Object> updateAudit(Information information){
        Map<String,Object> map =new HashMap<>();
        try {
            informationService.InformationUpdate(information);
            map.put("result",true);
        } catch (Exception e) {
            map.put("result",false);
            e.printStackTrace();
        }
        return map;
    }

}
